/**
 * 2010(c) Copyright Oceansoft Information System Co.,LTD. All rights reserved.
 * <p>
 * Compile: JDK 1.6+
 * <p>
 * 版权所有(C)：江苏欧索软件有限公司
 * <p>
 * 公司名称：江苏欧索软件有限公司
 * <p>
 * 公司地址：中国苏州科技城青山路1号
 * <p>
 * 网址: http://www.oceansoft.com.cn
 * <p>
 * 作者: 090922(陈伟)
 * <p>
 * 文件名: com.oceansoft.mobile.econsole.modules.api.controller.ApiDriverInfoController
 * <p>
 * 类产生时间: 2014-11-14 16:19
 * <p>
 * 负责人: 090922(陈伟)
 * <p>
 * Email:javacspring@gmail.com
 * <p>
 * 项目组 : 苏州公安移动门户
 * <p>
 * 部门: 手持技术部
 * <p>
 * <p>
 */
package com.oceansoft.mobile.econsole.modules.api.controller;

import com.oceansoft.mobile.econsole.modules.api.service.IDriverInfoApiService;
import com.oceansoft.mobile.econsole.modules.api.service.IDriverInfoService;
import com.oceansoft.mobile.econsole.modules.base.entity.Result;
import com.oceansoft.mobile.econsole.vehicle.service.IVehicleService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import static org.springframework.web.bind.annotation.RequestMethod.*;

/**
 * 驾驶员相关信息控制器
 *
 * @author chenw
 * @time 2014-11-14 16:19
 */
@RestController
@RequestMapping("api/bind")
public class ApiDriverInfoController {

    @Resource
    private IDriverInfoService driverInfoService;

    @Resource
    private IDriverInfoApiService driverInfoApiService;
    
    @Resource
    private IVehicleService vehicleService;

    /**
     * 供内网DCN监听程序调用
     * 1、当内网应用监听到临时表有新增记录时 调用此路径
     * 2、通过身份证号查询内网接口 获取车辆及驾驶证信息
     * 3、将内网接口返回的数据保存至 T_APP_DRIVER_INFO_API 表并通过网闸同步至外网
     *
     * @return Result
     */
    @RequestMapping(value = "dcn/save/{sfzh}", method = GET)
    public Result saveInfoAndroid(@PathVariable("sfzh") String sfzh) {
        return driverInfoApiService.saveInfoBySfzh(sfzh);
    }

    /**
     * 供外网DCN监听程序使用 推送消息给手机端
     *
     * @return
     */
    @RequestMapping(value = "dcn/push/{sfzh}/{mobile}", method = GET)
    public Result driverlist(@PathVariable("sfzh") String sfzh, @PathVariable("mobile") String mobile) {
        return driverInfoApiService.pushBindInfo(sfzh, mobile);
    }

    /**
     * 绑定车辆信息
     *
     * @param
     * @return Result
     */
    @RequestMapping(method = GET)
    public Result bindInfo(HttpServletRequest request) {return driverInfoService.bindInfo(request);
    }
    
    /**
     * 绑定车辆信息（解决ios无法调用）
     * @return
     */
    @RequestMapping(value="v2",method = GET)
    public Result bindInfo2(HttpServletRequest request) {
        return driverInfoService.bindInfo( request);
    }

    /**
     * 加载绑定驾驶证信息
     *
     * @param userId 用户ID
     * @return Result
     */
    @RequestMapping(value = "driver/{user_id}", method = GET)
    public Result loadDriveBindInfo(@PathVariable("user_id") String userId) {
        return driverInfoService.loadDriveBindInfo(userId);
    }

    /**
     * 加载车辆绑定信息
     *
     * @param userId 用户ID
     * @return Result
     */
    @RequestMapping(value = "vehicle/{user_id}", method = GET)
    public Result loadVehicleBindInfo(@PathVariable("user_id") String userId) {
        return driverInfoService.loadVehicleBindInfo(userId);
    }

    /**
     * 移除绑定信息
     *
     * @param pk 主键
     * @return Result
     */
    @RequestMapping(value = "undo/{pk}", method = DELETE)
    public Result removeBind(@PathVariable("pk") int pk) {
        return driverInfoService.removeDriverBindInfo(pk);
    }
    
    /**
     * 根据身份证号查询驾驶证信息
     * @param sfzh
     * @return
     */
    @RequestMapping(value = "info/driver/{sfzh}", method = GET)
    public Result loadDriverInfo(@PathVariable("sfzh") String sfzh) {
        return vehicleService.loadDriverInfo(sfzh);
    }
    
    /**
     * 根据身份证号查询车辆信息
     * @param sfzh
     * @return
     */
    @RequestMapping(value = "info/vehicle/{sfzh}", method = GET)
    public Result loadVehicleInfo(@PathVariable("sfzh") String sfzh) {
        return vehicleService.loadVehicleInfo(sfzh);
    }
}
